import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Cache } from "../../../cache/Cache";
import { PetExploreAreaInfo } from "../../../resource/info/PetExploreAreaInfo";
import { EPrictUnit } from "../../../../../Message/Public/EPrictUnit";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class PetExploreRewardWindow
    
    export  class PetExploreRewardWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._skipAreaArray = [];
            this._areas = [];
            this._areasCheckBoxArray = [];
            this.setSize(340, 230);
            this.titleHeight = 28;
            this.title = Language.getString(54495);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(17, 39, 305, 180, this);
            ObjCreate.createBitmap(ImagesConst.Fire, 40, 40, this);
            this._rbTxt = ObjCreate.createTextField(Language.getString(54591), 65, 50, 220, 20, this, GlobalStyle.textFormat6);
            this._rbTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._costCheckBox = ObjCreate.createCheckBox(Language.getString(54496), 40, 90, 220, 25, this);
            this._costCheckBox.visible = false;
            ObjCreate.createTextField(Language.getString(54497), 40, 147, 220, 20, this);
            this._costTxt = ObjCreate.createTextField("0YB", 180, 147, 220, 20, this);
            this._unitBitmap = ObjCreate.createBitmap(ImagesConst.Yuanbao, 200, 147, this);
            ObjCreate.createBitmap(ImagesConst.Fire, 40, 162, this);
            this._tipTxt = ObjCreate.createTextField("", 65, 170, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipTxt.htmlText = Language.getString(54498);
            this._getBtn = ObjCreate.createGButton(Language.getString(54499), 135, 190, 70, 26, this);
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            return;
        }

        /* internal  */updateSkipInfo(): void
        {
            var loc1=null;
            var loc4=null;
            this._cost = 0;
            this._areasCheckBoxArray = [];
            this._skipAreaArray = Cache.instance.petExplore.getSkipAreaArray();
            var loc2=this._skipAreaArray.length;
            var loc3=Cache.instance.petExplore.exploreDrawRewards.drawAreas;
            var loc5=0;
            while (loc5 < loc2) 
            {
                loc1 = this._skipAreaArray[loc5] as PetExploreAreaInfo;
                (loc4 = ObjCreate.createCheckBox(loc1.name, 40 + loc5 % 3 * 100, 65 + Math.floor(loc5 / 3) * 20, 130, 28, this)).name = loc5.toString();
                loc4.addEventListener(flash.events.Event.CHANGE, this.onCheckBoxChangeHandler);
                if (loc3.indexOf(loc1.area) == -1) 
                {
                    loc4.enabled = true;
                }
                else 
                {
                    loc4.enabled = false;
                    loc4.label = loc1.name + Language.getString(54592);
                }
                this._areasCheckBoxArray.push(loc4);
                ++loc5;
            }
            this.updateCost();
            return;
        }

        /* internal  */onCheckBoxChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.updateCost();
            return;
        }

        /* internal  */updateCost(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=null;
            this._cost = 0;
            this._areas = [];
            this._unit = EPrictUnit._EPriceUnitGold;
            var loc4=0;
            while (loc4 < this._areasCheckBoxArray.length) 
            {
                loc1 = this._areasCheckBoxArray[loc4] as GCheckBox;
                loc2 = int(loc1.name);
                if (loc1.selected) 
                {
                    loc3 = this._skipAreaArray[loc2] as PetExploreAreaInfo;
                    this._unit = loc3.drawUnit;
                    this._cost = this._cost + loc3.drawCost;
                    this._areas.push(loc3.area);
                }
                ++loc4;
            }
            this._unitBitmap.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(this._unit));
            this._costTxt.text = this._cost.toString();
            this._unitBitmap.x = this._costTxt.x + this._costTxt.textWidth + 5;
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._areas.length == 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(54593));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreGetReward, this._areas));
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.updateSkipInfo();
            return;
        }

        /* internal */ /* var */_rbTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_costCheckBox: GCheckBox;

        /* internal */ /* var */_costTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_unitBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_skipAreaArray: Array<any>;

        /* internal */ /* var */_cost: int;

        /* internal */ /* var */_unit: int;

        /* internal */ /* var */_startAreaName: string="";

        /* internal */ /* var */_endAreaName: string="";

        /* internal */ /* var */_areas: Array<any>;

        /* internal */ /* var */_areasCheckBoxArray: Array<any>;
    }
